<template>
	<view class="content">
		<view class="Ultraman" v-for="(v,i) in ordeList">
			<view class="font_an">
				<view class="font_size">
					{{v.categoryName}}
				</view>
				<view class="font_anfei">
					平台服务费{{v.rate?v.rate:v.serviceFee}}
				</view>
			</view>
			<view class="font_anaio">
				联系电话{{v.phone}}
			</view>
			<view class="font_anaio">
				上门地址：{{v.provinceName+v.cityName+v.regionName+v.address}}
			</view>
			<view class="font_anaios"></view>
			<view class="font_antin">
				<view class="font_antin_se">
					上门时间：{{v.visitTime}}
				</view>
				<view class="font_antin_button" @click="jied(v.id)">
					接单
				</view>
			</view>
		</view>
		<bottom-tab url='/pages/index/index'></bottom-tab>
	</view>
</template>

<script>
	import {
		bind
	} from 'lodash';
	export default {
		data() {
			return {
				ordeList: [],
				socket: null
			}
		},
		onLoad(e) {
			console.log(token);
			this.oloda()
			uni.connectSocket({
				url: 'ws://42.97.44.90:9999/websocket/server/order/' + e.userId
			});
			uni.onSocketOpen(function(res) {
				console.log('WebSocket连接已打开！', res);
			});
			uni.onSocketMessage((res) => {
				console.log('收到服务器内容：' + res.data);
				let order = JSON.parse(res.data);
				console.log(order.category.name);
				console.log(order.order.categoryName=order.category.name);
				

				function removeOrderFromList(orderList, orderToRemove) {
					const index = orderList.indexOf(orderToRemove);
					if (index !== -1) {
						orderList.splice(index, 1);
					}
				}
				if (order.type == 1) {
					this.ordeList.unshift(order.order);
				} else {
					removeOrderFromList(this.orderList, order.order);
				}
			});
			uni.onSocketError(function(res) {
				console.log('WebSocket连接打开失败，请检查！');
			});
		},
		methods: {
			oloda() {
				this.$ajax('get', 'recovery/appointment_order/orderList', {
					pageSize: 10,
					pageNum: 1
				}).then((res) => {
					console.log(res,'11')
					if(res.code === 200){
						this.ordeList = res.rows
					} else {
						uni.navigateTo({
							url:'../index/Reclaimsetting'
						})
					}
				})
			},
			jied(e) {
				this.$ajax('get', '/recovery/appointment_order/receiveOrder/' + e).then((res) => {
					if (res.code == 200) {
						this.$api.msg('抢单成功')
						this.oloda()
						setTimeout(() => {
							uni.navigateTo({
								url: '../index/Recallslip'
							})
						}, 600)
					} else {
						this.$api.msg(res.msg)
					}
				})
			}
		},
		mounted() {
			// #ifdef H5
			// 关闭左侧返回箭头
			var a = document.getElementsByClassName('uni-page-head-hd')[0]
			a.style.display = 'none';
			// #endif  
		},
	}
</script>

<style>
	page {
		background-color: #f1f1f1;
	}

	.font_antin {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 5px;
	}

	.font_antin_se {
		color: #a1a4a3;
	}

	.font_antin_button {
		width: 80px;
		text-align: center;
		line-height: 30px;
		height: 30px;
		border-radius: 25px;
		font-weight: 500;
		color: #fff;
		background-image: linear-gradient(to right, #26a5fa, #268afe);
	}

	.Ultraman {
		width: 90%;
		margin: 10px auto;
		background-color: #fff;
		border-radius: 10px;
		padding: 10px;
	}

	.font_anaios {
		background-color: #dfdfdf;
		height: 1px;
		width: 100%;
	}

	.font_anaio {
		margin: 10px 0;
		font-weight: 500;
		font-size: 18px;
	}

	.font_an {
		display: flex;
		align-items: center;

	}

	.font_anfei {
		background-color: #fef0e0;
		color: #fc9823;
		padding: 2px 10px;
		font-size: 14px;
		margin-left: 10px;
	}

	.font_size {
		font-weight: 600;
		font-size: 20px;
	}
</style>